package com.didd.core.exception;

import com.didd.core.common.base.ResultCode;
import com.didd.core.common.base.ResultStatus;
import lombok.Getter;

/**
 * 业务异常基类
 * @author diddd
 * @date 2019/6/24
 */
@Getter
public class BizException extends RuntimeException {

    /**
     * 异常枚举
     */
    private ResultStatus resultStatus;

    /**
     * 默认发送预警消息
     */
    private static final boolean DEFAULT_EARLY_WARNING = false;

    /**
     * 是否发送预警消息, 默认是
     */
    protected boolean warning = DEFAULT_EARLY_WARNING;

    public BizException() {
        super(ResultCode.FAIL_BIZ.fetchMessage());
    }

    public BizException(ResultStatus resultStatus) {
        super(resultStatus.fetchMessage());
        this.resultStatus = resultStatus;
    }

    public BizException(String message) {
        super(message);
    }

    public BizException(String message, Throwable cause) {
        super(message, cause);
    }

    public BizException(Throwable cause) {
        super(cause);
    }

    public BizException(boolean warning) {
        super();
        this.warning = warning;
    }

    public BizException(boolean warning, ResultStatus resultStatus) {
        super(resultStatus.fetchMessage());
        this.resultStatus = resultStatus;
        this.warning = warning;
    }

    public BizException(boolean warning, String message) {
        super(message);
        this.warning = warning;
    }

    public BizException(boolean warning, String message, Throwable cause) {
        super(message, cause);
        this.warning = warning;
    }

    public BizException(boolean warning, Throwable cause) {
        super(cause);
        this.warning = warning;
    }

    public boolean isWarning() {
        return warning;
    }
}
